var ECharts;
$(document).ready(function () {
    require.config({
        baseUrl: ctx + '/resource/plugins/echarts4',
        paths: {
            echarts: 'echarts',
            roma: 'theme/roma'
        }
    });
    require(
        [
            'echarts',
            'roma'
        ],
        function (ec) {
            ECharts = ec;
            MiddleWareInformationViewController();//中间件基本信息
            middleware_fw_zt = ECharts.init(document.getElementById('middleware_fw_zt'), 'roma');//工作状态
            queryMiddleWareFwState();
            middleware_ddx = ECharts.init(document.getElementById('middleware_ddx'), 'roma');//堆大小
            queryKpi_ddx();
            middleware_kxddx = ECharts.init(document.getElementById('middleware_kxddx'), 'roma');//空闲堆大小
            queryKpi_kxddx();
            middleware_ysyddx = ECharts.init(document.getElementById('middleware_ysyddx'), 'roma');//已使用堆大小
            queryKpi_ysyddx();
            middleware_qqdlcd = ECharts.init(document.getElementById('middleware_qqdlcd'), 'roma');//请求队列长度
            queryKpi_qqdlcd();
            middleware_dsyl = ECharts.init(document.getElementById('middleware_dsyl'), 'roma');//堆使用率
            queryMiddleWare_dsyl();
            middleware_dsyl_qjfb = ECharts.init(document.getElementById('middleware_dsyl_qjfb'), 'roma');//堆使用率区间分布
            queryMiddleWare_dsyl_qjfb();
            middleware_ljsyl = ECharts.init(document.getElementById('middleware_ljsyl'), 'roma');//连接使用率
            queryMiddleWare_ljsyl();
            middleware_ljsyl_qjfb = ECharts.init(document.getElementById('middleware_ljsyl_qjfb'), 'roma');//连接使用率区间分布
            queryMiddleWare_ljsyl_qjfb();
        }
    );

});


var infoList = [];//中间件基本信息
infoList.push("KPI-Weblogic-all-1");
infoList.push("KPI-Weblogic-all-10");
infoList.push("KPI-Weblogic-all-14");
infoList.push("KPI-Weblogic-all-3");
infoList.push("KPI-Weblogic-all-4");
infoList.push("KPI-Weblogic-all-8");
infoList.push("KPI-Weblogic-all-9");

//中间件基本信息
function MiddleWareInformationViewController() {
    var str = infoList.toString();
    $.ajax({
        url: ctx + "/load/queryInfo",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&RESU=" + str,
        success: function (data) {
            var map = JSON.parse(data);
            var list1 = map["KPI-Weblogic-all-1"];
            var list2 = map["KPI-Weblogic-all-3"];
            var list3 = map["KPI-Weblogic-all-8"];
            var list4 = map["KPI-Weblogic-all-9"];
            var list5 = map["KPI-Weblogic-all-14"];
            var list6 = map["KPI-Weblogic-all-10"];
            var list7 = map["KPI-Weblogic-all-4"];
            var tablel = "<tr>" +
                "<th><span >" + "指标名" + "</span></th>" +
                "<th><span >" + "采集值" + "</span></th>" +
                "</tr>";
            if (list1.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "管理IP" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list1[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list1[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list2.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "名称" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list2[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list2[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list3.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "版本号" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list3[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list3[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list4.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "激活时间" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list4[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list4[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list5.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "管理等级" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list5[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list5[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list6.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "备注信息" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list6[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list6[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            if (list7.length == 0) {
                tablel += "<tr>" +
                    "<td><span >" + "是否管理服务器" + "</span></td>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<td><span >" + list7[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list7[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            $("#middleware_info").append(tablel);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//工作状态
//FM-00-04-009-01
function queryMiddleWareFwState() {
    $.ajax({
        url: ctx + "/load/queryNum",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&KPI_CODE=" + "KPI-Weblogic-all-7" + "&DATE_TYPE=" + DATE_TYPE  + "&CLASS_NAME=" + CLASS_NAME,
        success: function (data) {
            var cpuState = JSON.parse(data);
            var mydata;
            for(var i=0;i<cpuState.length;i++){
                var a = cpuState[i].SUCCESS_VALUE;
                var b = cpuState[i].COUNT_VALUE;
            }
            option = {
                tooltip: {
                    formatter: "{a} <br/>{b} : {c}%"
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {show: true},
                        // restore: {show: true},
                        // saveAsImage: {show: true}
                    }
                },
                series: [
                    {
                        name: '',
                        type: 'gauge',
                        splitNumber: 10,       // 分割段数，默认为5
                        axisLine: {            // 坐标轴线
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: [[0.2, '#ff4500'], [0.8, '#48b'], [1, '#228b22']],
                                width: 8
                            }
                        },
                        axisTick: {            // 坐标轴小标记
                            splitNumber: 10,   // 每份split细分多少段
                            length: 12,        // 属性length控制线长
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: 'auto'
                            }
                        },
                        axisLabel: {           // 坐标轴文本标签，详见axis.axisLabel
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto'
                            }
                        },
                        splitLine: {           // 分隔线
                            show: true,        // 默认显示，属性show控制显示与否
                            length: 30,         // 属性length控制线长
                            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
                                color: 'auto'
                            }
                        },
                        pointer: {
                            width: 5
                        },
                        title: {
                            show: true,
                            offsetCenter: [0, '-40%'],       // x, y，单位px
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                fontWeight: 'bolder'
                            }
                        },
                        detail: {
                            formatter: '{value}%',
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto',
                                fontWeight: 'bolder'
                            }
                        },
                        data: []
                    }
                ]
            };//仪表盘结束
            var cpuName = "";
            var succ = [];
            var sun = [];
            var p_value = 0;
            var q_value = 0;
            var succs = 0;
            var sums = 0;
            if (DATE_TYPE == "showYear") {
                for (var j = 0; j < cpuState.length; j++) {
                    p_value = parseInt(cpuState[j].SUCCESS_VALUE);
                    succ.push(p_value);
                    q_value = parseInt(cpuState[j].COUNT_VALUE);
                    sun.push(q_value);
                    cpuName = cpuState[j].KPI_NAME;
                }
                for (var k = 0; k < succ.length; k++) {
                    succs += succ[k];
                    sums += sun[k];
                }
                /*alert(succs);alert(sums);*/
                mydata = [{value: parseInt(succs / sums * 100), name: cpuName}];
            } else {
                for (var i = 0; i < cpuState.length; i++) {
                    mydata = [{value: parseInt(cpuState[i].SUCCESS_VALUE / cpuState[i].COUNT_VALUE * 100), name: cpuState[i].KPI_NAME}];
                }
            }

            if (a == undefined || b == undefined) {
                var table = "<h3 style='margin-top: 180px;padding-left: 140px;'>" + "暂无数据" + "</h3>";
                $("#middleware_fw_zt").html(table);
            } else {
                option.series[0].data = mydata;
                middleware_fw_zt.setOption(option);
            }
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });

}

//堆大小
function queryKpi_ddx() {
    var timeHorizon = '';
    if (DATE_TYPE == 'showWeek') {
        timeHorizon = 'showOneWeek';
    } else if (DATE_TYPE == 'showMonth') {
        timeHorizon = 'showOneMonth';
    } else if (DATE_TYPE == 'showYear') {
        timeHorizon = 'showOneYear';
    } else {
        timeHorizon = 'showYesToday';
    }
    $.ajax({
        url: ctx + "/kpiContrast/queryKpiContrastInfo",
        type: "post",
        data: {extUnitId: EXT_UNIT_ID, kpiCode: 'KPI-Weblogic-all-19', timeHorizon: timeHorizon},
        success: function (data) {
            var list = JSON.parse(data);
            var ydata = [];
            var avgValue = [];
            var maxValue = [];
            var mixValue = [];
            var modelValue = [];
            if (list != null && list.length != 0) {
                for (var i = 0; i < list.length; i++) {
                    if (DATE_TYPE == "showWeek") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showMonth") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showYear") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[1]);
                    } else {
                        x_value = list[i].DATA_TIME.replace(' ', '-').split("-");
                        ydata.push(x_value[3]);
                    }
                    avgValue.push(list[i].AVG_VALUE);
                    maxValue.push(list[i].MAX_VALUE);
                    mixValue.push(list[i].MIN_VALUE);
                    modelValue.push(list[i].MODEL_VALUE);
                }
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['平均值', '最大值', '最小值', '众数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ydata,
                        axisLabel: {
                            interval: 0,
                            rotate: 0
                        }
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '平均值',
                            type: 'line',
                            stack: '总量',
                            data: avgValue
                        },
                        {
                            name: '最大值',
                            type: 'line',
                            stack: '总量',
                            data: maxValue
                        },
                        {
                            name: '最小值',
                            type: 'line',
                            stack: '总量',
                            data: mixValue
                        },
                        {
                            name: '众数',
                            type: 'line',
                            stack: '总量',
                            data: modelValue
                        }
                    ]
                };
                middleware_ddx.setOption(option);
            } else {
                $('#middleware_ddx').html("<h3 style='margin-top: 200px;padding-left: 340px;'>暂无数据</h3>");
            }
        },
        error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//空闲堆大小
function queryKpi_kxddx() {
    var timeHorizon = '';
    if (DATE_TYPE == 'showWeek') {
        timeHorizon = 'showOneWeek';
    } else if (DATE_TYPE == 'showMonth') {
        timeHorizon = 'showOneMonth';
    } else if (DATE_TYPE == 'showYear') {
        timeHorizon = 'showOneYear';
    } else {
        timeHorizon = 'showYesToday';
    }
    $.ajax({
        url: ctx + "/kpiContrast/queryKpiContrastInfo",
        type: "post",
        data: {extUnitId: EXT_UNIT_ID, kpiCode: 'KPI-Weblogic-all-20', timeHorizon: timeHorizon},
        success: function (data) {
            var list = JSON.parse(data);
            var ydata = [];
            var avgValue = [];
            var maxValue = [];
            var mixValue = [];
            var modelValue = [];
            if (list != null && list.length != 0) {
                for (var i = 0; i < list.length; i++) {
                    if (DATE_TYPE == "showWeek") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showMonth") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showYear") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[1]);
                    } else {
                        x_value = list[i].DATA_TIME.replace(' ', '-').split("-");
                        ydata.push(x_value[3]);
                    }
                    avgValue.push(list[i].AVG_VALUE);
                    maxValue.push(list[i].MAX_VALUE);
                    mixValue.push(list[i].MIN_VALUE);
                    modelValue.push(list[i].MODEL_VALUE);
                }
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['平均值', '最大值', '最小值', '众数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ydata,
                        axisLabel: {
                            interval: 0,
                            rotate: 0
                        }
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '平均值',
                            type: 'line',
                            stack: '总量',
                            data: avgValue
                        },
                        {
                            name: '最大值',
                            type: 'line',
                            stack: '总量',
                            data: maxValue
                        },
                        {
                            name: '最小值',
                            type: 'line',
                            stack: '总量',
                            data: mixValue
                        },
                        {
                            name: '众数',
                            type: 'line',
                            stack: '总量',
                            data: modelValue
                        }
                    ]
                };
                middleware_kxddx.setOption(option);
            } else {
                $('#middleware_kxddx').html("<h3 style='margin-top: 200px;padding-left: 340px;'>暂无数据</h3>");
            }
        },
        error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//已使用堆大小
function queryKpi_ysyddx() {
    var timeHorizon = '';
    if (DATE_TYPE == 'showWeek') {
        timeHorizon = 'showOneWeek';
    } else if (DATE_TYPE == 'showMonth') {
        timeHorizon = 'showOneMonth';
    } else if (DATE_TYPE == 'showYear') {
        timeHorizon = 'showOneYear';
    } else {
        timeHorizon = 'showYesToday';
    }
    $.ajax({
        url: ctx + "/kpiContrast/queryKpiContrastInfo",
        type: "post",
        data: {extUnitId: EXT_UNIT_ID, kpiCode: 'KPI-Weblogic-all-35', timeHorizon: timeHorizon},
        success: function (data) {
            var list = JSON.parse(data);
            var ydata = [];
            var avgValue = [];
            var maxValue = [];
            var mixValue = [];
            var modelValue = [];
            if (list != null && list.length != 0) {
                for (var i = 0; i < list.length; i++) {
                    if (DATE_TYPE == "showWeek") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showMonth") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showYear") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[1]);
                    } else {
                        x_value = list[i].DATA_TIME.replace(' ', '-').split("-");
                        ydata.push(x_value[3]);
                    }
                    avgValue.push(list[i].AVG_VALUE);
                    maxValue.push(list[i].MAX_VALUE);
                    mixValue.push(list[i].MIN_VALUE);
                    modelValue.push(list[i].MODEL_VALUE);
                }
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['平均值', '最大值', '最小值', '众数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ydata,
                        axisLabel: {
                            interval: 0,
                            rotate: 0
                        }
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '平均值',
                            type: 'line',
                            stack: '总量',
                            data: avgValue
                        },
                        {
                            name: '最大值',
                            type: 'line',
                            stack: '总量',
                            data: maxValue
                        },
                        {
                            name: '最小值',
                            type: 'line',
                            stack: '总量',
                            data: mixValue
                        },
                        {
                            name: '众数',
                            type: 'line',
                            stack: '总量',
                            data: modelValue
                        }
                    ]
                };
                middleware_ysyddx.setOption(option);
            } else {
                $('#middleware_ysyddx').html("<h3 style='margin-top: 200px;padding-left: 340px;'>暂无数据</h3>");
            }
        },
        error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//请求队列长度
function queryKpi_qqdlcd() {
    var timeHorizon = '';
    if (DATE_TYPE == 'showWeek') {
        timeHorizon = 'showOneWeek';
    } else if (DATE_TYPE == 'showMonth') {
        timeHorizon = 'showOneMonth';
    } else if (DATE_TYPE == 'showYear') {
        timeHorizon = 'showOneYear';
    } else {
        timeHorizon = 'showYesToday';
    }
    $.ajax({
        url: ctx + "/kpiContrast/queryKpiContrastInfo",
        type: "post",
        data: {extUnitId: EXT_UNIT_ID, kpiCode: 'KPI-Weblogic-all-25', timeHorizon: timeHorizon},
        success: function (data) {
            var list = JSON.parse(data);
            var ydata = [];
            var avgValue = [];
            var maxValue = [];
            var mixValue = [];
            var modelValue = [];
            if (list != null && list.length != 0) {
                for (var i = 0; i < list.length; i++) {
                    if (DATE_TYPE == "showWeek") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showMonth") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[2]);
                    } else if (DATE_TYPE == "showYear") {
                        x_value = list[i].DATA_TIME.split("-");
                        ydata.push(x_value[1]);
                    } else {
                        x_value = list[i].DATA_TIME.replace(' ', '-').split("-");
                        ydata.push(x_value[3]);
                    }
                    avgValue.push(list[i].AVG_VALUE);
                    maxValue.push(list[i].MAX_VALUE);
                    mixValue.push(list[i].MIN_VALUE);
                    modelValue.push(list[i].MODEL_VALUE);
                }
                option = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['平均值', '最大值', '最小值', '众数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ydata,
                        axisLabel: {
                            interval: 0,
                            rotate: 0
                        }
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '平均值',
                            type: 'line',
                            stack: '总量',
                            data: avgValue
                        },
                        {
                            name: '最大值',
                            type: 'line',
                            stack: '总量',
                            data: maxValue
                        },
                        {
                            name: '最小值',
                            type: 'line',
                            stack: '总量',
                            data: mixValue
                        },
                        {
                            name: '众数',
                            type: 'line',
                            stack: '总量',
                            data: modelValue
                        }
                    ]
                };
                middleware_qqdlcd.setOption(option);
            } else {
                $('#middleware_qqdlcd').html("<h3 style='margin-top: 200px;padding-left: 340px;'>暂无数据</h3>");
            }
        },
        error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//堆使用率
function queryMiddleWare_dsyl() {
    $.ajax({
        url: ctx + "/load/queryLoad",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&KPI_CODE=" + "KPI-Weblogic-all-21" + "&DATE_TYPE=" + DATE_TYPE + "&CLASS_NAME=" + CLASS_NAME,
        success: function (data) {
            var map = JSON.parse(data);
            var list = map.list;
            var listTb = map.listTb;
            var listHb = map.listHb;
            var xdata = [];
            var ydata1 = [];
            var ydata2 = [];
            var ydata3 = [];
            var x_value = [];
            for (var i = 0; i < list.length; i++) {
                var a = list[i].AVG_VALUE;
                var b = listTb[i].AVG_VALUE;
                // var c = listHb[i].AVG_VALUE;
            }
            if (a == undefined || b == undefined) {
                var table = "<h3 style='margin-top: 200px;padding-left: 340px;'>" + "暂无数据" + "</h3>";
                $("#middleware_dsyl").html(table);
            } else {
                if (DATE_TYPE == "showWeek") {
                    for (var i = 0; i < list.length; i++) {
                        x_value = list[i].DATA_TIME.split("-");
                        xdata.push(x_value[2]);
                        ydata1.push(list[i].AVG_VALUE);
                        ydata2.push(listTb[i].AVG_VALUE);
                        ydata3.push(listHb[i].AVG_VALUE);
                    }
                } else if (DATE_TYPE == "showMonth") {
                    for (var i = 0; i < list.length; i++) {
                        x_value = list[i].DATA_TIME.split("-");
                        xdata.push(x_value[2]);
                        ydata1.push(list[i].AVG_VALUE);
                        ydata2.push(listTb[i].AVG_VALUE);
                        ydata3.push(listHb[i].AVG_VALUE);
                    }
                    /*  option.xAxis.axisLabel.formatter='{value} d';*/
                } else if (DATE_TYPE == "showYear") {
                    for (var i = 0; i < list.length; i++) {
                        // xdata.push(list[i].DATA_TIME);
                        x_value = list[i].DATA_TIME.split("-");
                        xdata.push(x_value[1]);
                        ydata1.push(list[i].AVG_VALUE);
                        ydata2.push(listTb[i].AVG_VALUE);
                        /*ydata3.push(listHb[i].AVG_VALUE);*/
                    }
                } else {
                    for (var i = 0; i < list.length; i++) {
                        x_value = list[i].DATA_TIME.replace(' ', '-').split("-");
                        xdata.push(x_value[3]);
                        ydata1.push(list[i].AVG_VALUE);
                        ydata2.push(listTb[i].AVG_VALUE);
                        ydata3.push(listHb[i].AVG_VALUE);
                    }
                }
                option = {
                    tooltip: {
                        trigger: 'axis',
                    },
                    legend: {
                        data: ['昨日', '同比', '环比'],
                        textStyle: {
                            color: '#AAAAAA'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        axisLabel: {
                            /*formatter:'{value} h',*/
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                        data: xdata
                    }],
                    yAxis: [{
                        type: 'value',
                        max: 100,//Y轴最大值 不写的话自动调节
                        axisLabel: {
                            formatter: '{value} %',
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        }
                    }],
                    series: [
                        {
                            name: '昨日',
                            type: 'line',
                            color: '#EFB700',
                            data: ydata1
                        },
                        {
                            name: '同比',
                            type: 'line',
                            color: '#FF0A0E',
                            data: ydata2
                        },
                        {
                            name: '环比',
                            type: 'line',
                            color: '#0AFFBD',
                            data: ydata3
                        }
                    ]
                };
                middleware_dsyl.setOption(option);
            }
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//堆使用率区间分布
function queryMiddleWare_dsyl_qjfb() {
    $.ajax({
        url: ctx + "/load/queryNum",
        type: "post",
        data: "DATE_TYPE=" + DATE_TYPE + "&EXT_UNIT_ID=" + EXT_UNIT_ID + "&KPI_CODE=" + "KPI-Weblogic-all-21" + "&CLASS_NAME=" + CLASS_NAME,
        success: function (data) {
            var memoryNum = JSON.parse(data);
            var xdata = [];
            var num1 = '';
            var min_value = '';
            var max_value = '';
            var group = '';
            var p = [];
            var values = [];
            var result = [0, 0, 0, 0, 0];
            var temp = '';
            var temp1 = '';
            var hkh = '';
            var myMap = new Map();
            var sum = 0;
            for (var i = 0; i < memoryNum.length; i++) {
                var a = memoryNum[i].GROUP_VALUE;
            }
            if (a == undefined) {
                var table = "<h3 style='margin-top: 200px;padding-left: 340px;'>" + "暂无数据" + "</h3>";
                $("#middleware_dsyl_qjfb").html(table);
            } else {
                if (DATE_TYPE != "showYear") {//，分割分完的截取每个元素的倒数第一个或者第二个双引号的值{"0.0~20.0":"289"，"20.0~40.0":"290，"40.0~60.0":"291"}
                    for (var i = 0; i < memoryNum.length; i++) {
                        hkh = memoryNum[i].GROUP_VALUE.substring(1, memoryNum[i].GROUP_VALUE.lastIndexOf('}'));
                        num1 = hkh.split(',');
                        min_value = memoryNum[i].Y_MIN_VALUE;
                        max_value = memoryNum[i].Y_MAX_VALUE;
                        group = memoryNum[i].VALUE_GROUP;
                        for (j = 0; j < num1.length; j++) {
                            temp = num1[j].substring(num1[j].lastIndexOf(':"') + 2, num1[j].lastIndexOf('"'));
                            temp1 = num1[j].substring(1, num1[j].lastIndexOf('":'));
                            myMap.set(temp1, temp);
                        }
                        if (myMap.get("0.0~20.0") != null) {
                            xdata.push(myMap.get("0.0~20.0"));
                        } else {
                            xdata.push(0);
                        }
                        if (myMap.get("20.0~40.0") != null) {
                            xdata.push(myMap.get("20.0~40.0"));
                        } else {
                            xdata.push(0);
                        }
                        if (myMap.get("40.0~60.0") != null) {
                            xdata.push(myMap.get("40.0~60.0"));
                        } else {
                            xdata.push(0);
                        }
                        if (myMap.get("60.0~80.0") != null) {
                            xdata.push(myMap.get("60.0~80.0"));
                        } else {
                            xdata.push(0);
                        }
                        if (myMap.get("80.0~100.0") != null) {
                            xdata.push(myMap.get("80.0~100.0"));
                        } else {
                            xdata.push(0);
                        }
                    }
                } else {
                    for (var i = 0; i < memoryNum.length; i++) {
                        hkh = memoryNum[i].GROUP_VALUE.substring(1, memoryNum[i].GROUP_VALUE.lastIndexOf('}'));
                        num1 = hkh.split(',');
                        min_value = memoryNum[i].Y_MIN_VALUE;
                        max_value = memoryNum[i].Y_MAX_VALUE;
                        group = memoryNum[i].VALUE_GROUP;
                        for (var j = 0; j < num1.length; j++) {
                            temp = num1[j].substring(num1[j].lastIndexOf(':"') + 2, num1[j].lastIndexOf('"'));
                            temp1 = num1[j].substring(1, num1[j].lastIndexOf('":'));
                            if (temp) {
                                sum = parseInt(sum) + parseInt(temp);
                            }
                            myMap.set(temp1, sum);
                        }
                    }
                    if (myMap.get("0.0~20.0") != null) {
                        xdata.push(myMap.get("0.0~20.0"));
                    } else {
                        xdata.push(0);
                    }
                    if (myMap.get("20.0~40.0") != null) {
                        xdata.push(myMap.get("20.0~40.0"));
                    } else {
                        xdata.push(0);
                    }
                    if (myMap.get("40.0~60.0") != null) {
                        xdata.push(myMap.get("40.0~60.0"));
                    } else {
                        xdata.push(0);
                    }
                    if (myMap.get("60.0~80.0") != null) {
                        xdata.push(myMap.get("60.0~80.0"));
                    } else {
                        xdata.push(0);
                    }
                    if (myMap.get("80.0~100.0") != null) {
                        xdata.push(myMap.get("80.0~100.0"));
                    } else {
                        xdata.push(0);
                    }
                }
                option = {
                    color: ['#23CBFE'],
                    title: {
                        text: '',
                        subtext: ''
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    legend: {
                        data: ['堆使用率区间分布'],
                        textStyle: {
                            color: '#AAAAAA'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01],
                        splitLine: {
                            show: false
                        },
                        axisLabel: {
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        }
                    },
                    yAxis: {
                        type: 'category',
                        splitLine: {
                            show: true
                        },
                        axisLabel: {
                            /* formatter:'{value} %',*/
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                        data: [
                            (100 - 0) / 5,
                            (100 - 0) / 5 * 2,
                            (100 - 0) / 5 * 3,
                            (100 - 0) / 5 * 4,
                            (100 - 0) / 5 * 5,
                        ]
                    },
                    series: [
                        {
                            name: '堆使用率区间分布',
                            type: 'bar',
                            barWidth: 30,
                            data: xdata
                        }
                    ]

                };
                middleware_dsyl_qjfb.setOption(option);
            }
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}
